<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>开启头部工具栏 - 数据表格</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="${pageContext.request.contextPath }/back/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="${pageContext.request.contextPath }/back/style/admin.css" media="all">
</head>
<body>

<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>组件</cite></a>
    <a><cite>数据表格</cite></a>
    <a><cite>开启头部工具栏</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
      <div class="layui-card">
        <div class="layui-card-header">入住信息</div>
        <div class="layui-card-body">
          <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">房间号</label>
                <div class="layui-input-block">
                  <input type="text" name="loginname" id="roomNum" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">房间类型</label>
                <div class="layui-input-block">
                  <select name="role" id="AllrtName">
                    <option id="rtName">请选择</option>
                    <%--<option id="rtName" value="0">单人间</option>
                    <option value="1">双人间</option>
                    <option value="2">大床房</option>
                    <option value="3">总统套房</option>--%>
                  </select>
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">处理人</label>
                <div class="layui-input-block">
                  <input type="text" name="adminName" id="adminName"  placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-inline">
                <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search" id="fuzzyQuery">
                  <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                </button>
              </div>
              <div class="layui-inline">
                <button class="layui-btn layuiadmin-btn-admin" data-type="add">添加</button>
              </div>
            </div>
          </div>

          <table class="layui-hide" id="test-table-toolbar" lay-filter="test-table-toolbar"></table>

          <script type="text/html" id="test-table-toolbar-toolbarDemo">
            <div class="layui-btn-container">
              <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
              <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
              <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
            </div>
          </script>

          <script type="text/html" id="buttonTpl">
            {{#  if(d.inStatus == 0){ }}
            <span class="layui-badge layui-bg-black">已结算</span>
            {{#  } else { }}
            <span class="layui-badge layui-bg-green">未结算</span>
            {{#  } }}
          </script>
          <script type="text/html" id="test-table-toolbar-barDemo">
            <a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
          </script>
        </div>
      </div>
    </div>
  </div>
</div>

<script src="${pageContext.request.contextPath }/back/layui/layui.js"></script>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
  $(function(){
    var content="";
    $.get("${pageContext.request.contextPath}/RoomTypeController/queryRtNameRoomType",function(data){
      $.each(data,function(index,type){
        content+="<option id=\"rtName\" value="+data[index].rtName+">"+data[index].rtName+"</option>";
        /*content+="<li><a data-filter=\".Budget\" name=\"spc\" value=\"1\">"+data[index].rtName+"</a></li>";*/
      })
      $("#AllrtName").append(content);
    })
  })
  function renderdata(roomNum,rtName,adminName){
    layui.config({
      base: '${pageContext.request.contextPath }/back/' //静态资源所在路径
    }).extend({
      index: 'lib/index' //主入口模块
    }).use(['index', 'table'], function(){
      var admin = layui.admin
              ,$ = layui.$
              ,form = layui.form
              ,table = layui.table;
      table.render({
        elem: '#test-table-toolbar'
        ,url: '${pageContext.request.contextPath }/viewLivein/getAllLivein?roomNum='+roomNum+'&rtName='+rtName+'&adminName='+adminName
        ,toolbar: '#test-table-toolbar-toolbarDemo'
        ,title: '入住信息'
        ,cols: [[
          {type: 'checkbox', fixed: 'left'}
          ,{field:'iid', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
          ,{field:'roomNum', title:'房间号', width:100, edit: 'text'}
          ,{field:'rtName', title:'房间类型', width:100, edit: 'text'}
          ,{field:'rtPrice', title:'价格', width:100, edit: 'text'}
          ,{field:'iforegift', title:'押金', width:100, edit: 'text'}
          ,{field:'userName', title:'姓名', width:100}
          ,{field:'userTel', title:'手机号',width:210}
          ,{field:'userRealId', title:'身份证号', width:240}
          ,{field:'icount', title:'人数', width:80, edit: 'text'}
          ,{field:'itime', title:'入住时间',width:120, edit: 'text'}
          ,{field:'days', title:'预住天数', width:100, edit: 'text'}
          ,{field:'remark', title:'备注',width:150, edit: 'text'}
          ,{field:'adminName', title:'处理人', width:80, edit: 'text'}
          ,{field: 'inStatus', title:'处理状态', templet: '#buttonTpl', width: 120, align: 'center', edit: 'text'}
          ,{fixed: 'right', title:'操作', toolbar: '#test-table-toolbar-barDemo', width:150}
        ]]
        ,page: true
      });

      //头工具栏事件
      table.on('toolbar(test-table-toolbar)', function(obj){
        var checkStatus = table.checkStatus(obj.config.id);
        switch(obj.event){
          case 'getCheckData':
            var data = checkStatus.data;
            layer.alert(JSON.stringify(data));
            break;
          case 'getCheckLength':
            var data = checkStatus.data;
            layer.msg('选中了：'+ data.length + ' 个');
            break;
          case 'isAll':
            layer.msg(checkStatus.isAll ? '全选': '未全选');
            break;
        };
      });

      //监听行工具事件
      table.on('tool(test-table-toolbar)', function(obj){
        var data = obj.data;
        if(obj.event === 'del'){
          layer.confirm('真的删除么', function(index){
            var IId=data.iid;
            $.get("${pageContext.request.contextPath }/viewLivein/upLivein",{IId:IId},function(){
              window.parent.location.reload();
            },"json")
            /*obj.del();*/
            layer.close(index);
          });
        } else if(obj.event === 'edit'){
          layer.confirm('确认修改', function(index){
            layer.alert(JSON.stringify(data));
            //提交 Ajax 成功后，静态更新表格中的数据
            //$.ajax({});
            layer.close(index);
          });
        }
      });
      //事件
      var active = {
        add: function(){
          layer.open({
            type: 2
            ,title: '添加入住信息'
            ,content: '${pageContext.request.contextPath }/BackController/chekinform'
            ,area: ['450px', '600px']
            ,btn: ['确定', '取消']
            ,yes: function(index, layero){
              var iframeWindow = window['layui-layer-iframe'+ index]
                      ,submitID = 'LAY-user-back-submit'
                      ,submit = layero.find('iframe').contents().find('#'+ submitID);

              //监听提交
              iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                var field = data.field; //获取提交的字段

                //提交 Ajax 成功后，静态更新表格中的数据
                //$.ajax({});
                table.reload('LAY-user-front-submit'); //数据刷新
                layer.close(index); //关闭弹层
              });

              submit.trigger('click');
            }
          });
        }
      }
      $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
      });
    });
  }
  $(function() {
    //渲染数据
    renderdata("","","");

    //模糊查询
    $("#fuzzyQuery").click(function(){
      var roomNum=$("#roomNum").val();
      var rtName=$("#rtName").val();
      var adminName=$("#adminName").val();
      renderdata(roomNum,rtName,adminName);
    })
  })

</script>
</body>
</html>